package main

import (
	"flag"
	"fmt"
	"modelgenerate/converter"
)

func main() {
	// 解析命令行参数
	user := flag.String("user", "root", "username")
	host := flag.String("host", "localhost", "mysql host")
	port := flag.String("port", "3306", "mysql host port")
	password := flag.String("password", "root", "password")
	table := flag.String("database", "test", "database name")
	dir := flag.String("dir", "models", "save dir")
	orm := flag.String("orm", "gorm", "orm name")
	timePackage := flag.String("timepkg", "time", "custom your time package name")
	pointerTime := flag.String("timepoint", "no", "custom your time field to pointer, such as *time.Time (Yes/no)")
	flag.Parse()

	// 生成 dsn
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", *user, *password, *host, *port, *table)

	// 开始生成
	err := converter.NewTable2Struct().
		Config(&converter.T2tConfig{
			// 如果字段首字母本来就是大写, 就不添加tag, 默认false添加, true不添加
			RmTagIfUcFirsted: false,
			// tag的字段名字是否转换为小写, 如果本身有大写字母的话, 默认false不转
			TagToLower: false,
			// 字段首字母大写的同时, 是否要把其他字母转换为小写,默认false不转换
			UcFirstOnly: false,
			//// 每个struct放入单独的文件,默认false,放入同一个文件(暂未提供)
			SeperatFile: true,
			// 时间的包名
			TimePackage: *timePackage,
			// 时间是否为指针
			TimePointer: *pointerTime,
		}).
		Dsn(dsn).
		SavePath(fmt.Sprintf("./%s", *dir)).
		RealNameMethod("TableName").
		EnableJsonTag(true).
		PackageName(*dir).
		TagKey(*orm).
		Run()
	if err != nil {
		panic(err)
		return
	}
}
